using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using System.Globalization;

namespace LyonMag
{
    public partial class FileDetail : PhoneApplicationPage
    {
        string title = string.Empty;
        string header = string.Empty;
        string imageurl = string.Empty;
        string category = string.Empty;
        string date = string.Empty;
        string commentscount = string.Empty;
        string id = string.Empty;
        string thumbtitle = string.Empty;
        public FileDetail()
        {
            InitializeComponent();
        }
        private void stkTwitter_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                ShareLinkTask obj_share = new ShareLinkTask();
                obj_share.Message = title;
                obj_share.Title = title;
                obj_share.LinkUri = new Uri("http://www.lyonmag.com");
                obj_share.Show();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void stkEmail_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                ShareLinkTask obj_share = new ShareLinkTask();
                obj_share.Message = title;
                obj_share.Title = title;
                obj_share.LinkUri = new Uri("http://www.lyonmag.com");
                obj_share.Show();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {

                NavigationContext.QueryString.TryGetValue("title", out title).ToString();
                NavigationContext.QueryString.TryGetValue("header", out header).ToString();
                NavigationContext.QueryString.TryGetValue("imageurl", out imageurl).ToString();
                NavigationContext.QueryString.TryGetValue("category", out category).ToString();
                NavigationContext.QueryString.TryGetValue("date", out date).ToString();
                NavigationContext.QueryString.TryGetValue("commentscount", out commentscount).ToString();
                NavigationContext.QueryString.TryGetValue("thumbtitle", out thumbtitle);
                NavigationContext.QueryString.TryGetValue("id", out id).ToString();
                System.Windows.Media.Imaging.BitmapImage nit = new System.Windows.Media.Imaging.BitmapImage();
                nit.UriSource = new Uri(imageurl);
                img.Source = nit;
                txtTile.Text = category;
                txtThumb.Text = thumbtitle;
                if (date != "")
                {
                    DateTime MyDateTime;
                    MyDateTime = new DateTime();
                    MyDateTime = Convert.ToDateTime(date);
                    string inputFormat = "dd-MM-yyyy HH:mm:ss";
                    txtDate.Text = MyDateTime.ToString(inputFormat);
                }
                //  txtDate.Text = date.ToString();
                txtDescription.Text = header;
                txtHeader.Text = title;
                txtccount.Text = "(" + commentscount + ")";
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void StackPanel_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/comments.xaml?id=" + id + "&pagename=Files", UriKind.RelativeOrAbsolute));
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            try
            {
                ApplicationBar.IsVisible = false;
                App.appSettingsGuid["accoutid"] = "test";
                App.appSettingsGuid.Save();
            }
            catch (Exception ex)
            {
                ApplicationBar.IsVisible = false;
                App.appSettingsGuid["accoutid"] = "test";
                App.appSettingsGuid.Save();
                ex.Message.ToString();
            }
        }
        private void stkFacebook_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            try
            {
                ShareLinkTask obj_share = new ShareLinkTask();
                obj_share.Message = title;
                obj_share.Title = title;
                obj_share.LinkUri = new Uri("http://www.lyonmag.com");
                obj_share.Show();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
    }
}